<template>
  <SceneContainerTree
    ref="sceneTreeRef"
    v-loading="treeLoading"
    :key="!treeLoading"
    class="biz-container"
    :table-common-attr="filter_tableCommonAttr"
    :table-body-data="filter_tableBodyData"
    :all-btns-emit-form-item-meta-config="filter_allBtnsEmitFormItemMetaConfig"
    :dialog-form-item-dynmic-config-list="filter_dialogFormItemDynmicConfigList"
    :tool-bar-config="filter_toolBarConfig"
    :operation-btns-config="filter_operationBtnsConfig"
    v-bind="$attrs"
  ></SceneContainerTree>
</template>
<script>
  export default {
    name: "BizTreeSimple",
    inheritAttrs: false,
  };
</script>
<script setup>
  import {
    ref,
    reactive,
    shallowRef,
    shallowReactive,
    computed,
    getCurrentInstance,
    toRefs,
    watch,
    provide,
    onMounted,
    useAttrs,
  } from "vue";
  import SceneContainerTree from "@gd-accbuild-ui/scene-container/scene-container-tree/scene-container-tree.vue";

  // scene-container-gen:start
  import useGetCurUiTemplateInfo from "@gd-accbuild-core/hooks/useGetCurUiTemplateInfo";
  import useCanvasRender from "@gd-accbuild-ui/biz-ui/hooks/useCanvasRender/useCanvasRender";
  import buildInBizTemplateProps from "@gd-accbuild-core/hooks/buildInBizTemplateProps";
  import useMergeMeta from "@gd-accbuild-core/hooks/useMergeMeta";
  import globalStyles from "@gd-accbuild-core/theme-chalk/pc-admin/js.module.scss";
  import { useStore } from "@gd-accbuild-core/store/hackVueStore";
  const _store = useStore();
  const { proxy: vm } = getCurrentInstance();

  const props = defineProps({
    ...buildInBizTemplateProps,
  });

  const _emits = defineEmits(["biz-tree-simple:filter-data:init"]);

  const {
    crudServiceVmTemplateConfig,
    isUseStaticResource,
    setterCrudServiceVmTemplateConfig,
    allBtnsEmitFormItemMetaConfig,
    filter_allBtnsEmitFormItemMetaConfig,
    ////
    filter_toolBarConfig,
    filter_operationBtnsConfig,
    filter_setterAllTableBtnsConfig,
    ////
    filter_tableCommonAttr,
    filter_tableBodyData,
    filter_dialogFormItemDynmicConfigList,
    filter_setterRemoteTableConfig,
    filter_getFirstItemAppendReqParamsIntoSearchForm,
    ////////
    fillFieldsIntoAddForm,
    appendFieldsIntoSearchForm,
  } = useMergeMeta({ props });
  /////////////////////
  /////树相关

  const hasLeftTree = ref(false);
  const treeLoading = ref(true);
  ///////////////////
  //组件增删改查接口的附加参数,用于设计器渲染请求 是否转发到优速搭服务器
  const initMetaAndData = ({
    allOverrideParams = [{ templateInnerSearchPath: "templateProps.filter_tableCommonAttr", appendReqParams: {} }],
  }) => {
    treeLoading.value = true;
    const appendReqParams =
      Array.isArray(allOverrideParams) && allOverrideParams.length === 1
        ? allOverrideParams[0]?.appendReqParams ?? {}
        : {};

    useGetCurUiTemplateInfo({
      templateName: vm.$options.name,
      templateIdx: props.templateIdx,
      templateInnerSearchPath: "templateProps.filter_tableCommonAttr",
      isUseStaticResource: isUseStaticResource.value,
      staticResource: props.staticResource,
      appendReqParams,
      allOverrideParams,
      store: _store,
    })
      .then((templateState) => {
        const hasTree = !templateState.hasOwnProperty("vaildFailureTemplateInnerSearchPath");
        const appendReqParams = {};
        if (hasTree) {
          //////////////////////
          setterCrudServiceVmTemplateConfig("tree", templateState);
          //////////////////////

          filter_setterRemoteTableConfig(templateState, _emits);

          filter_setterAllTableBtnsConfig(templateState);
          //////////////////////
          filter_getFirstItemAppendReqParamsIntoSearchForm(appendReqParams);
          treeLoading.value = false;
          hasLeftTree.value = hasTree;
        }
        /* 传递后面一个Promise链需要的参数 */
        return Promise.resolve({
          store: templateState.store,
          appendReqParams,
        });
      })
      .then(async (res) => {})
      .catch((err) => {
        console.log(err);
      });
  };

  initMetaAndData({
    allOverrideParams: [
      {
        templateInnerSearchPath: "templateProps.filter_tableCommonAttr",
        appendReqParams: {},
      },
    ],
  });

  /////////
  provide("crudServiceVmTemplateConfig", crudServiceVmTemplateConfig);
  /** 以下两个是左树点击后传给右表的参数,需要在左树点击时间内赋值 */
  provide("fillFieldsIntoAddForm", fillFieldsIntoAddForm);
  provide("appendFieldsIntoSearchForm", appendFieldsIntoSearchForm);
  const sceneTreeRef = ref(null);

  // scene-container-gen:end
  defineExpose({
    sceneTreeRef,
    initMetaAndData,
  });
  ///////////////////////////
</script>
<style lang="scss" scoped>
  .biz-container {
    //width: #{$--accbuild-tree-default-width};
    float: left;

    //height: 100%;
    :deep(.tree-content-container) {
      overflow-y: scroll;
      height: 100%; //300px;//
      //max-height: 600px;//calc(100vh - (48px + 52px + 40px + 40px + 50px + 200px));
    }
  }
</style>
